//
//  TabarBaseViewController.m
//  CatSport
//
//  Created by yonghui liu on 2020/5/15.
//  Copyright © 2020 刘永慧. All rights reserved.
//

#import "TabarBaseViewController.h"
#import "HomeViewController.h"
#import "DiscoverViewController.h"
#import "NavigationBaseViewController.h"


@interface TabarBaseViewController ()

@end

@implementation TabarBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIViewController *homeVC = [self createTabBarController:NSStringFromClass([HomeViewController class]) title:@"首页" imageName:@"tab0" selectImageName:@"tab0_select" isNeedNavigation:NO];
    UIViewController *disVC = [self createTabBarController:NSStringFromClass([DiscoverViewController class]) title:@"发现" imageName:@"tab1" selectImageName:@"tab1_select" isNeedNavigation:YES];
    self.viewControllers = [NSArray arrayWithObjects:homeVC,disVC, nil];
}

- (UIViewController *)createTabBarController:(NSString *)controllerName title:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName isNeedNavigation:(BOOL)isNeed{
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    attributes[NSForegroundColorAttributeName] = [UIColor blackColor];
    attributes[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    NSMutableDictionary *selectAttributes = [NSMutableDictionary dictionary];
    selectAttributes[NSForegroundColorAttributeName] = [UIColor orangeColor];
    selectAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    Class cls = NSClassFromString(controllerName);
    UIViewController *controller = [[cls alloc] init];
    controller.tabBarItem.title = title;
    [controller.tabBarItem setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [controller.tabBarItem setTitleTextAttributes:selectAttributes forState:UIControlStateSelected];
    UIImage *image = [UIImage imageNamed:imageName];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.tabBarItem.image = image;
    UIImage *selectImage = [UIImage imageNamed:selectImageName];
    selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.tabBarItem.selectedImage = selectImage;
    if (isNeed) {
        NavigationBaseViewController *navVC = [[NavigationBaseViewController alloc] initWithRootViewController:controller];
        return navVC;
    }
    return controller;
}



/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
